#include <stdlib.h>

#define MAXALLOCSIZE 65000L

#define MAXALLOC(type) (MAXALLOCSIZE / sizeof(type))

#define xmalloc(type,cnt) \
	(((cnt) > MAXALLOC(type)) ? NULL : (type *) malloc(sizeof(type)*(cnt)))

#define xalloc(type,cnt) \
	(((cnt) > MAXALLOC(type)) ? NULL : (type *) calloc(sizeof(type), (cnt)))

#define xrealloc(old,type,cnt) \
	(((cnt) > MAXALLOC(type)) \
	  ? (old) : (type *) realloc((void *) (old),sizeof(type)*(cnt)))

#define xfree(p) free(p)

